﻿<?
	
	error_reporting(E_ERROR);
	session_start();
	header ('Content-type: text/html; charset=utf-8');   
	require_once "../db/connection.inc"; 
	include_once "JSON.php";
	$action = $_REQUEST["action"];
	
	$json = new Services_JSON(); 
	
	if("$action"=="info"){
		$idCimitero=$_REQUEST["vc__ID"] ;
		
		exit("ddd");	
	}
	
	if("$action"=="combo"){
		$start = $_REQUEST["start"] ;
		$end = $_REQUEST["limit"]  ;
		if("$start"=="") $start=0;
		if("$end"=="") $end=20;
		
		$sort = $_REQUEST["sort"];
		$direction = $_REQUEST["dir"];
		
		if("$sort"=="") {
			$sort = 'ID';
			$direction='';
		}	
		
		$_REQUEST["vc__ID"] = $_REQUEST["vc__ID"] . "*" ; 
			
		$sql = "
			SELECT ID,DESCRIZION, concat(ID ,concat(' - ',DESCRIZION) ) AS DESCESTESA
			FROM cimiteri
			ORDER BY $sort $direction
            LIMIT $start,$end
			 
		" ; 
		$dt =rs($sql,$_REQUEST);
		
		$sqlCount = "
			SELECT count(*) As total 
            FROM cimiteri 
		" ;
		
		$totalFromSession = $_SESSION["CIMITERI_COMBO_TOTAL"];
		
		if($start==0 || !isset($totalFromSession) ){
			$dtc =rs($sqlCount,$_REQUEST);
			$values = $dtc->getRow();
			$totalFromSession = $values["total"] ;
			$_SESSION["CIMITERI_COMBO_TOTAL"]=$totalFromSession;
		} 
		 
		exit( recordsetToJson($dt,$totalFromSession,$sql )  );
		
	} 	
	echo "false";	
	
?>